package com.cn.wanxi.thread;

import com.sun.xml.internal.ws.spi.db.DatabindingException;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class MyTimer {
    public static void main(String[] args) throws ParseException {
//        final int[] a = {0};
        Timer timer = new Timer();
//        定位到十点四十
        Date date=new Date();
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        System.out.println(dateFormat.format(date));
        date=dateFormat.parse("2022-5-19 10:45:00");
        final int[] a = {0};
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                a[0]++;
                System.out.println(a[0]);
            }
        },date,1000);



//
//        timer.schedule(new TimerTask() {
//            @Override
//            public void run() {
////                System.out.println(a[0]++);
////                if (a[0] == 6) {
////                    System.out.println("定时器取消");
////                    timer.cancel();
////                }
//            }
//        }, 4000, 2000);
    }
}
